import datetime
import os.path
import sys
import time
from selenium import webdriver
from webdriver_manager.microsoft import EdgeChromiumDriverManager
from selenium.webdriver.edge.service import Service as EdgeService

class Driver:
    driver=""
    def __init__(self):
        self.driver=webdriver.Edge(service=EdgeService(EdgeChromiumDriverManager().install()))
        # 隐式等待
        self.driver.implicitly_wait(3)

    # 截图
    def getScreenShot(self):
        dirname=datetime.datetime.now().strftime("%Y-%m-%d")
        # 如果不存在../images/dirname，就创建该目录
        if not os.path.exists("../images/"+dirname):
            os.mkdir("../images/"+dirname)
        filename=datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")
        # 能知道调用本接口的接口名
        funcname=sys._getframe().f_back.f_code.co_name+"-"
        # 目标：../images/2025-3-14/接口名-2025-3-14-202101.png
        self.driver.save_screenshot("../images/"+dirname+"/"+funcname+filename+".png")

# 创建Driver对象
BolgDriver=Driver()


